package org.herui.campus.service.properties;

import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.herui.campus.properties.PropertyValueInfo;
import org.shan.spring.base.BaseController;
import org.shan.spring.base.annotations.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "参数管理接口", tags = {"参数管理接口"})
@SysLog(title = "参数管理")
@RestController
@RequestMapping("/properties")
public class PropertiesController extends BaseController {


    @Autowired
    private ManagerProperties managerProperties;


    @ApiOperation("查询所有属性")
    @GetMapping("/get/all")
    public ResponseData<Map<String, Map<String, List<PropertyValueInfo>>>> getAllProperties() {
        List<BaseProperties> baseProperties = managerProperties.getBaseProperties();
        Map<String, Map<String, List<PropertyValueInfo>>> mapMap = new HashMap<>();
        for (BaseProperties properties: baseProperties){
            Map<String, List<PropertyValueInfo>> map = properties.getMap();
            String title = properties.getTitle();
            mapMap.put(title, map);
        }
        return result(mapMap);
    }

    @ApiOperation("设置属性")
    @GetMapping("/set")
    public Response change(String title, String region, PropertyValueInfo propertyValueInfo) {
        List<BaseProperties> baseProperties = managerProperties.getBaseProperties();
        Map<String, Map<String, List<PropertyValueInfo>>> mapMap = new HashMap<>();
        for (BaseProperties properties: baseProperties){
            if (properties.getTitle().equals(title)){
                properties.set(region, propertyValueInfo);
            }
        }
        return result();
    }

}